package financial.sharing.center.invoice.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import financial.sharing.center.common.enums.ResponseContext;
import financial.sharing.center.common.utils.PageSize;
import financial.sharing.center.common.utils.R;
import financial.sharing.center.invoice.model.entity.Invoice;
import financial.sharing.center.invoice.service.InvoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Map;

/**
 * @ClassName InvoiceController
 * @Description TODO
 * @Author guoyuhang
 * @ @csdn https://blog.csdn.net/qq_40788718
 * @Date 2021/5/13
 * @Version 1.0
 */
@RestController
@RequestMapping(value = "/invoice/invoice")
public class InvoiceController {

    @Autowired
    private InvoiceService invoiceServiceImpl;

    @PostMapping(value = "get/all/invoice")
    public R getAllInvoice(String selectInvoiceContext,
                           Integer selectInvoiceTypeValue,
                           Integer selectInvoiceColorValue,
                           Integer currentPage){
        PageHelper.startPage(currentPage, PageSize.PAGESIZE_TEN);
        PageInfo<Invoice> result = this.invoiceServiceImpl.getAllInvoice(selectInvoiceContext,selectInvoiceTypeValue,selectInvoiceColorValue);
        return R.ok(result);
    }

    @PostMapping(value = "create/one/invoice")
    public R createOneInvoice(String invoiceContext,
                              Integer invoiceTypeValue,
                              Integer invoiceColorValue){
        Integer result = this.invoiceServiceImpl.createOneInvoice(invoiceContext,invoiceTypeValue,invoiceColorValue);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "compile/one/invoice")
    public R compileOneInvoice(@RequestBody Invoice invoice){
        Integer result = this.invoiceServiceImpl.compileOneInvoice(invoice);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "delete/one/invoice")
    public R deleteOneInvoice(Integer id){
        Integer result = this.invoiceServiceImpl.deleteOneInvoice(id);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "get/map/invoice")
    public Map<Integer, BigDecimal> getMapInvoice(){
        return this.invoiceServiceImpl.getMapInvoice();
    }

}
